package com.internetCafes.spms.web.sys.service.impl;

import com.internetCafes.spms.core.generic.GenericDao;
import com.internetCafes.spms.core.generic.GenericServiceImpl;
import com.internetCafes.spms.core.model.pageModel.DataGrid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.internetCafes.spms.web.sys.dao.SmsLogMapper;
import com.internetCafes.spms.web.sys.model.SmsLog;
import com.internetCafes.spms.web.sys.service.SmsLogService;


/**
 *  SmsLogService 实现类
 *
 * @author Sunny
 * @email rekeeper2011@hotmail.com
 * @date 2020-05-19 10:24:40
 */
@Service("smsLogService")
public class SmsLogServiceImpl extends GenericServiceImpl<SmsLog, String> implements SmsLogService {

    @Autowired
    private SmsLogMapper smsLogMapper;

    @Override
    public List<SmsLog> query(Map<String, Object> params) {
        return smsLogMapper.selectByParams(params);
    }

    @Override
    public SmsLog findById(String id) {
        return smsLogMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<SmsLog> queryByIds(List<String> ids) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("ids", ids);
        return smsLogMapper.selectByParams(params);
    }

    @Override
    public List<SmsLog> page(Map<String, Object> params, int page, int rows) {
        params.put("page", page);
        params.put("rows", rows);
        return smsLogMapper.selectByParams(params);
    }

    @Override
    public long count(Map<String, Object> params) {
        return smsLogMapper.countByParams(params);
    }

    @Override
    public SmsLog findFirst(Map<String, Object> params) {
        List<SmsLog> list = smsLogMapper.selectByParams(params);
        SmsLog smsLog =null;
        if (list != null && list.size() > 0) {
            smsLog =list.get(0);
        }
        return smsLog;
    }

    @Override
    public int save(SmsLog smsLog) {
        return smsLogMapper.insert(smsLog);
    }

    @Override
    public int saveBatch(List<SmsLog> smsLogList) {
        return smsLogMapper.insertBatch(smsLogList);
    }

    @Override
    public int saveSelective(SmsLog smsLog) {
        return smsLogMapper.insertSelective(smsLog);
    }

    @Override
    public int update(SmsLog smsLog) {
        return smsLogMapper.updateByPrimaryKey(smsLog);
    }

    @Override
    public int updateSelective(SmsLog smsLog) {
        return smsLogMapper.updateByPrimaryKeySelective(smsLog);
    }

    @Override
    public int delete(String id) {
        return smsLogMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int deleteBatch(List<String> ids) {
        return smsLogMapper.deleteBatchByPrimaryKey(ids);
    }

    @Override
    public void deleteBatch(String[] ids) {
        if(ids != null && ids.length > 0){
            for(String id : ids){
                delete(id);
            }
        }
    }

    @Override
    public GenericDao<SmsLog, String> getDao() {
        return smsLogMapper;
    }

    /**
	 * DataGrid
	 */
    @Override
    public DataGrid dataGrid(Map<String, Object> params, int pageNo, int pageSize) {

        List<SmsLog> smsLogList = page(params, (pageNo - 1 < 0 ? -1 : pageNo - 1) * pageSize, pageSize);
        long count = count(params);

        DataGrid dg = new DataGrid(smsLogList, count, pageSize, pageNo);
        return dg;
    }
}